package com.yimixian.app.model;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView.Recycler;
import android.support.v7.widget.RecyclerView.State;
import android.view.View;
import android.view.View.MeasureSpec;

public class MyLayoutManager extends LinearLayoutManager {

	public MyLayoutManager(Context context) {
		super(context);
	}
	private int measuredHieght;

	public MyLayoutManager(Context context, int measuredHieght) {
		super(context);
		this.measuredHieght = measuredHieght;
	}

	public MyLayoutManager(Context context, int orientation, boolean reverseLayout) {
		super(context, orientation, reverseLayout);
	}

	@Override
	public void onMeasure(Recycler recycler, State state, int widthSpec, int heightSpec) {

		View view = recycler.getViewForPosition(0);
		measureChild(view, widthSpec, heightSpec);
		int measuredWidth = View.MeasureSpec.getSize(widthSpec);
		int measuredHeight = view.getMeasuredHeight();
		setMeasuredDimension(measuredWidth, measuredHeight);


//		super.onMeasure(recycler, state, widthSpec, heightSpec);
//		System.out.println("haliluya#11111#***measuredHieght****" + measuredHieght);
//		if(state.getItemCount() > 0){
//			String height = "";
//			int measuredWidth = 200;
//			int measuredHeight = 200;
//			int maxHeight = 300;
//			for (int i = 0; i < state.getItemCount(); i++) {
//				View view = recycler.getViewForPosition(i);
//				measureChild(view, widthSpec, heightSpec);
//				measuredWidth = MeasureSpec.getSize(widthSpec);
//				measuredHeight = MeasureSpec.getSize(heightSpec);
//				System.out.println("haliluya#44445#***" + measuredWidth + "," + measuredHeight);
//				maxHeight = maxHeight < view.getMeasuredHeight() ? view.getMeasuredHeight() : maxHeight;
//				height += view.getMeasuredHeight() + ",";
//			}
//			setMeasuredDimension(measuredWidth, measuredHeight);
//			System.out.println("haliluya#2#*****"  + maxHeight + "**" + height);
//		}else{
//			super.onMeasure(recycler, state, widthSpec, heightSpec);
//		}
	}
}